<!DOCTYPE html>
<html>
<head>
	<title>文章</title>
	<meta name="keywords" content=""/>
	<meta name="description" content="">
	<include file="public@head"/>
</head>

<body class="body-white" id="top">
<include file="public@nav" />

<div class="container tc-main">
	<div class="row">
		<div class="col-md-3">
			<include file="public@usernav" />
		</div>
		<div class="col-md-9">
			<div class="tabs">
				<ul class="nav nav-tabs">
					<li><a href="#one" data-toggle="tab"><i class="fa fa-comments-o"></i> 我的文章</a></li>
					<li class="active"><a href="{:url('portal/article/add')}"><i class="fa fa-plus"></i> 发表文章</a></li>
				</ul>
				<div class="tab-content">
					<form class="form-horizontal js-ajax-form margin-top-20" action="{:url('portal/article/addPost')}" method="post">
						<div class="control-group">
							<label class="control-label" for="input-title">标题</label>
							<div class="controls">
								<input type="text" id="input-title" placeholder="标题" name="post[post_title]">
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="input-cid">文章分类</label>
							<div class="controls">
                                <input class="form-control" type="text" style="width:400px;" required value=""
                                       placeholder="请选择分类" onclick="doSelectCategory();" id="js-categories-name-input"
                                       readonly/>
                                <input class="form-control" type="hidden" value="" name="post[categories]"
                                       id="js-categories-id-input"/>
							</div>
						</div>
						<div>
							<label class="control-label" for="input-cid">发布时间</label>
							<div class="controls">
								<input class="form-control js-datetime" type="text" name="post[published_time]" value="{:date('Y-m-d H:i:s',time())}">
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="input-birthday">缩略图</label>
							<div class="controls">
								<div style="display: inline-block;text-align: center;">
									<input type="hidden" name="post[more][thumbnail]" id="thumbnail" value="">
									<a href="javascript:upload_one_image('图片上传','#thumbnail');">
										<img src="__TMPL__/public/assets/images/default-thumbnail.png" id="thumbnail-preview" width="135" style="cursor: pointer"/>
									</a>
									<input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
								</div>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="input-birthday">摘要</label>
							<div class="controls"><textarea class="form-control" name="post[post_excerpt]" style="height: 50px;" placeholder="请填写摘要"></textarea></div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="input-birthday">内容</label>
							<div class="controls"><script type="text/plain" id="content" name="post[post_content]"></script> </div>
						</div>
						<div class="control-group">
							<div class="controls">
								<button type="submit" class="btn js-ajax-submit" data-wait="1500">发表</button>
							</div>
						</div>
                     </form>
				</div>
			</div>
		</div>
	</div>
	<include file="public@footer" />
</div>
<!-- /container -->
<include file="public@scripts" />
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
    $(function () {

        editorcontent = new baidu.editor.ui.Editor();
        editorcontent.render('content');
        try {
            editorcontent.sync();
        } catch (err) {
        }

        $('.btn-cancel-thumbnail').click(function () {
            $('#thumbnail-preview').attr('src', '__TMPL__Public/assets/images/default-thumbnail.png');
            $('#thumbnail').val('');
        });
    });

    function doSelectCategory() {
        var selectedCategoriesId = $('#js-categories-id-input').val();
        open_iframe_layer("{:url('portal/Article/select')}?ids=" + selectedCategoriesId, '请选择分类', {
            area: ['700px', '400px'],
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //do something

                var iframeWin          = window[layero.find('iframe')[0]['name']];
                var selectedCategories = iframeWin.confirm();
                if (selectedCategories.selectedCategoriesId.length == 0) {
                    layer.msg('请选择分类');
                    return;
                }
                $('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
                $('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
                //console.log(layer.getFrameIndex(index));
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }
</script>
</body>
</html>